//
// Created by harrybao on 2019/4/4.
//

#ifndef CMAKE_DOUBLY_LIST_H
#define CMAKE_DOUBLY_LIST_H

class DoublyList
{
public:
    static void Insert(ListNode* node, ListNode* head)
    {
        Insert(node, head, head->next);
    }
    static void Insert(ListNode* node, ListNode* prev_node, ListNode* next_node)
    {
        //node->prev = prev_node;
        //node->next = next_node;
        //prev_node->next = node;
        //next_node->prev = node;

        Link(prev_node, node);
        Link(node, next_node);
    }
    static void Pop(ListNode* node)
    {
        Link(node->prev, node->next);
        node->prev = node;
        node->next = node;
    }
    static ListNode* Front(ListNode* head)
    {
        return head;
    }
    static bool Empty(ListNode* head)
    {
        return head->next == head;
    }
private:
    static void Link(ListNode* prev_node, ListNode* next_node)
    {
        prev_node->next = next_node;
        next_node->prev = prev_node;
    }
};


#endif //CMAKE_DOUBLY_LIST_H
